//解决多个接口同时发送网络请求时关闭showloading
let ajaxnum = 0;
export const http = (options) => {
  ajaxnum++;
  wx.showLoading({
    title: '加载中',
    mask:true
  });
  const BASE_URL = 'https://api-hmugo-web.itheima.net/api/public/v1';
  return new Promise((resolve,reject) => {
    wx.request({
      // url: BASE_URL + options.url,
      ...options,
      url:BASE_URL + options.url,
      success:(result) => {
        resolve(result.data.message)
      },
      fail:(error) => {
        reject(error)
      },
      //第三个回调函数 无论成功失败 都会调用
      complete:() => {
        ajaxnum--;
        if(ajaxnum == 0) {
          wx.hideLoading()
        }
      }
    })
  })
}